package com.example.administrator.printoutindemo.adapter;

import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.administrator.printoutindemo.R;
import com.example.administrator.printoutindemo.ShenPiyijianActivity;
import com.example.administrator.printoutindemo.bean.DaishenpiListBean;
import com.example.administrator.printoutindemo.http.SPUtil;

import java.util.ArrayList;
import java.util.List;


/**
 * Created by noc on 2019/4/9.
 */

public class ShenPiAdapter extends BaseAdapter {
private Context context;
    List<DaishenpiListBean> mlists = new ArrayList<>();
    LayoutInflater inflater;

    public ShenPiAdapter(Context context, List<DaishenpiListBean> mlists) {
        this.context = context;
        this.mlists = mlists;
        this.inflater=LayoutInflater.from(context);
    }

    public LayoutInflater getInflater() {
        return inflater;
    }

    public void setInflater(LayoutInflater inflater) {
        this.inflater = inflater;
    }

    @Override
    public int getCount() {
        return mlists.size();
    }

    @Override
    public Object getItem(int i) {
        return mlists.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
       ViewHolder holder=null;
        if (view==null){
            view=getInflater().inflate(R.layout.lingdaoshenpinitem,null);
            holder=new ViewHolder();
            holder.tv_sqr=view.findViewById(R.id.tv_sqr);
            holder.tv_rw=view.findViewById(R.id.tv_rw);
            holder.tv_cx=view.findViewById(R.id.tv_cx);
            holder.tv_ys=view.findViewById(R.id.tv_ys);
            holder.tv_sj=view.findViewById(R.id.tv_sj);
            holder.tv_shenpi=view.findViewById(R.id.tv_shenpi);
            holder.tv_sqsj=view.findViewById(R.id.tv_sqsj);
//            holder.tv_time=view.findViewById(R.id.tv_time);
//            holder.tv_rgs=view.findViewById(R.id.tv_rgs);
            view.setTag(holder);
        }else {
            holder= (ViewHolder) view.getTag();
        }
        if (mlists.get(i).getApplyDate()!=null){
            holder.tv_sqsj.setText(mlists.get(i).getApplyDate());
        }else {
            holder.tv_sqsj.setText("");
        }
        if (mlists.get(i).getApplicant()!=null){
            holder.tv_sqr.setText(mlists.get(i).getApplicant());
        }else {
            holder.tv_sqr.setText("");
        }
        if (mlists.get(i).getTaskDescription()!=null){
            holder.tv_rw.setText(mlists.get(i).getTaskDescription());
        }else {
            holder.tv_rw.setText("");
        }
        if (mlists.get(i).getModels()!=null){
            holder.tv_cx.setText(mlists.get(i).getModels());
        }else {
            holder.tv_cx.setText("");
        }
        if (String.valueOf(mlists.get(i).getBudget())!=null){
            holder.tv_ys.setText(String.valueOf(mlists.get(i).getBudget()));
        }else {
            holder.tv_ys.setText("");
        }
//        if (String.valueOf(mlists.get(i).getActualCost())!=null){
//            holder.tv_sj.setText(String.valueOf(mlists.get(i).getActualCost()));
//        }else {
//            holder.tv_sj.setText("");
//        }

        holder.tv_shenpi.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                context.startActivity(new Intent(context, ShenPiyijianActivity.class));
                SPUtil.putString(context,"peisongids",mlists.get(i).getDeliveryId()+"");
            }
        });
        return view;
    }
    class ViewHolder{
        TextView tv_sqr,tv_rw,tv_cx,tv_ys,tv_sj,tv_shenpi,tv_sqsj;
    }
    public void addAll(List<DaishenpiListBean> shenpi){
        mlists.addAll(shenpi);
        notifyDataSetChanged();
    }
}
